package org.example.cloudprviderpayment8001.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.example.cloudprviderpayment8001.annotion.Timeout;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
@Order(0)
public class TimoutAspect {
    @Pointcut("@annotation(org.example.cloudprviderpayment8001.annotion.Timeout)")
    public void pointcut(){}
    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable{
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        Method method = methodSignature.getMethod();
        boolean present = method.isAnnotationPresent(Timeout.class);
        if (present){
            Timeout annotation = method.getAnnotation(Timeout.class);
            int retry = annotation.retry();
            System.out.println(retry);
        }
        System.out.println("环绕");
        return joinPoint.proceed();
    }
}
